-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Activate bzlmod #1912
Activate bzlmod #1912
Conversation
030bbdd
to
de4fc78
Compare
🎉 All dependencies have been resolved ! |
This commit add a custom registry for bzlmod support. - It is used to access module from rules_nixpkgs until they are available on the central registry - It is used to access local versions of `rules_haskell` and `rules_haskell_nix` modules for testing.
The legacy io_tweag_rules_nixpkgs repository is not a bazel module, so with bzlmod, we use the modules provided with rules_nixpkgs instead.
This module should be used with bzlmod to install nix based toolchains. This way the main rules_haskell module does not depend on rules_nixpkgs.
- bzlmod is not setup yet in examples and tutorial directory
The docs folder has development dependencies that are not available from `rules_haskell_nix` and is not necessary for integration tests.
Various modules will need to reference the local registry with different relative paths.
For non development dependencies of rules_haskell which are not available as modules.
de4fc78
to
c555631
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work! Thank you!
This was a difficult task,
Just a couple minor comments.
@@ -1,414 +0,0 @@ | |||
"""Workspace rules (Nixpkgs)""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something to watch out for: Symlinks in Zip archives are problematic, so turning this file into a symlink may make .zip
bundles of rules_haskell unusable.
tools/runfiles/src/Bazel/Runfiles.hs
Outdated
import System.Info (os) | ||
|
||
-- | Bazel repository mapping for bzlmod | ||
-- See https://github.com/bazelbuild/proposals/blob/7c8da4a931d83db5c25abf85f6c486ad22d330e3/designs/2022-07-21-locating-runfiles-with-bzlmod.md | ||
type RepoMapping = [((String, String), String)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps out of scope for this PR, but I wonder if we could overhaul this module to use some better data structures than [a]
and String
, like Map
and perhaps even text
(though I guess we want to stick to core package dependencies).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to this file it seems that text
is only a core package since ghc-8.4
, but containers
is there for all the versions mentioned in the file (which start at ghc-7.10.1
).
I updated the library to use Data.Map.Strict
in this commit (the lookupDir
function makes use of Map.to_list
but I think it's fine since we need to iterate over (key,value) pairs in this case).
haskell/defs.bzl
Outdated
native.genrule( | ||
name = "{}_genrule".format(module_name), | ||
outs = ["{}.hs".format(module_name)], | ||
cmd = """ | ||
cat << EOF >> $@ | ||
{{-# LANGUAGE CPP #-}} | ||
module {} (create, createFromProgramPath, rlocation) where | ||
import qualified Bazel.Runfiles as RulesHaskellRunfiles | ||
create = RulesHaskellRunfiles.createFromCurrentFile __FILE__ | ||
createFromProgramPath = RulesHaskellRunfiles.createFromProgramPathAndCurrentFile (Just __FILE__) | ||
rlocation = RulesHaskellRunfiles.rlocation | ||
EOF | ||
""".format(module_name), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Maybe this could use Skylib's expand_template
or write_file
rule?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the PR to use expand_template
👍
e744032
to
9af561b
Compare
0c9a5e2
to
8d445fa
Compare
All the documentation is generated from the `rules_haskell` module.
8d445fa
to
8877ccc
Compare
Thanks! I addressed the comments (except for the symlink one for which I have no good solution at the moment). The required status checks of github need to be updated manually again to be able to merge, since new jobs were added to test bzlmod. |
done. |
Depends on #1911
This PR contains the changes necessary to activate bzlmod in the CI.
rules_haskell_nix
module is added, which is used to install nix toolchains with bzlmod. This way the mainrules_haskell
module does not have to depend onrules_nixpkgs
(other than as adev dependency
).@rules_haskell//haskell:nixpkgs.bzl
file is still available for backward compatibility (it is now a symlink to the file inrules_haskell_nix
).@rules_haskell//haskell:nixpkgs.bzl
symlink is also used byrules_haskell
itselft for testing, but only as a dev dependency.rules_haskell
andrules_haskell_nix
for testing..bazelrc
file is split into.bazelrc.common
and.bazelrc.bzlmod
. This way the various modules can share only the common part (they need to access the registry using different relative paths).rules_haskell_dependencies
extension contains dependencies which are always needed byrules_haskell
(as opposed to the ones fromnon_module_dev_dependencies
).rules_haskell_asterius
extension generates utility repository for asterius, and provide acustom
tag to be able to usewebpack
from a pre-existing npm setup.Changes to the runfiles library.
Since the name of repositories in the output base can change, the runfiles library must be able to resolve them.
As explained in this design document, this is done by parsing the
_repo_mapping
file which is now provided by bazel in the runfiles tree.Since each repository has its own mapping, there is also some logic to recover the name of the
current_repo
, which is the repository making use of the runfiles library. A troublesome case is when a haskell library with runfiles is beeing used by a binary of another module. In this case, we cannot rely on the binary path to recover thecurrent_repo
of the library.This is why a new
createFromCurrentFile
function was added to the runfiles library, to which we can pass the__FILE__
constant in order to recover the name of the module containing the library (similarly to what is mentioned in this section of the design document).This requires enabling the preprocessor which has some limitation (such as being incompatible with multiline string), so the haskell_runfiles helper rule is provided in
@rules_haskell//haskell:defs.bzl
, which generates a small wrapper around the mainrunfiles
library (to separate the usage of{-# LANGUAGE CPP #-}
from the rest of the code).Changes to the CI
rules_haskell_nix
module does not contains tests yet (it is tested by therules_haskell_tests
module in bzlmod mode), but at least buildifier should be added once more files are added to it (most notably the module extension to install nix toolchains).tutorial
andexample
folders do not containMODULE.bazel
files yet so they are not tested with bzlmod.